package solved;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayDeque;
import java.util.HashSet;

/*
ID:		liluyan1
LANG:	JAVA
TASK:	msquare
*/
public class msquare {
	public static void main(String[] args) throws IOException {
		BufferedReader f = new BufferedReader(new FileReader("msquare.in"));
		PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(
				"msquare.out")));
		new msquare().solve(f, out);
		out.close();
		System.exit(0);
	}
	
	ArrayDeque<State> queue;
	HashSet<String> visited;
	
	private void solve(BufferedReader f, PrintWriter out) throws IOException {
		String target = f.readLine().replaceAll(" ", "");
		
		queue = new ArrayDeque<State>();
		visited = new HashSet<String>();
		addState("12345678", null, null);
		
		while (!queue.isEmpty()) {
			State s = queue.remove();
			if (target.equals(s.state)) {
				StringBuffer sb = new StringBuffer();
				int step = 0;
				while (s!=null) {
					if (s.action!=null) sb.insert(0, s.action);
					step++;
					s = s.parent;
				}
				out.println(step-1);
				out.println(sb.toString());
				return;
			}
			
			addState(runA(s.state), "A", s);
			addState(runB(s.state), "B", s);
			addState(runC(s.state), "C", s);
		}
		
		out.println("NONE");
	}
	
	private String runA(String s) {
		return new StringBuffer(s).reverse().toString();
	}
	
	private String runB(String s) {
		char[] c = s.toCharArray();
		return "" + c[3] + c[0] + c[1] + c[2] + c[5] + c[6] + c[7] + c[4];
	}
	
	private String runC(String s) {
		char[] c = s.toCharArray();
		return "" + c[0] + c[6] + c[1] + c[3] + c[4] + c[2] + c[5] + c[7];
	}
	
	private void addState(String state, String action, State parent) {
		if (visited.contains(state)) return;
		queue.add(new State(state, action, parent));
		visited.add(state);
	}
	
	private class State {
		String state;
		String action;
		State parent;
		
		public State(String state, String action, State parent) {
			this.state = state;
			this.action = action;
			this.parent = parent;
		}
	}
}
